package com.ghost.manager
{
	import com.ghost.data_struct.HashMap;
	import com.ghost.event.Pop_win_event;
	import com.ghost.utils.Debug;
	
	import fl.transitions.Blinds;
	import fl.transitions.Fade;
	import fl.transitions.Fly;
	import fl.transitions.Photo;
	import fl.transitions.Transition;
	import fl.transitions.TransitionManager;
	import fl.transitions.easing.Strong;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	
	import flashx.textLayout.formats.Direction;

	/**
	 * @author ghost
	 * 特效管理
	 */	
	public class Effect_manager
	{
		private static var instance:Effect_manager;
		public static function getInstance():Effect_manager
		{
			if(instance == null)
			{
				instance = new Effect_manager();
			}
			return instance;
		}
		public function Effect_manager()
		{
		}
		private var transiton:Transition;
		/**
		 * @param mc 目标对象
		 * @param obj 特效数据对象
		 */		
		public function set_effect(mc:*,obj:Object):void
		{
			transiton = TransitionManager.start(mc,obj);
			//var transition_manager:TransitionManager = new TransitionManager(mc);
			//var transiton:Transition = transition_manager.startTransition(obj);
			transiton.addEventListener("transitionInDone",creat_function(added_Handler,mc));
			transiton.addEventListener("transitionOutDone",creat_function(removed_Handler,mc));
		}
		//移入舞台
		private function added_Handler(mc:*):void
		{
			mc.dispatchEvent(new Pop_win_event(Pop_win_event.added_effect_str));
			Debug.log(mc.toString()+"addeffect in stage");
		}
		//移出舞台
		private function removed_Handler(mc:*):void
		{
			mc.dispatchEvent(new Pop_win_event(Pop_win_event.removed_effect_event));
			Debug.log(mc.toString()+"addeffect out stage");
		}
		private function creat_function(f:Function,mc:*):Function
		{
			return function(e:Event):void
			{
				f.call(null,mc);
				remove_event();
			}
		}
		private function remove_event():void
		{
			transiton.removeEventListener("transitionInDone",creat_function(added_Handler,null));
			transiton.removeEventListener("transitionOutDone",creat_function(removed_Handler,null));
		}
	}
}